package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import com.itheima.dao.MapDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.CheckMap;
import com.itheima.service.MapService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Transactional
@Service(interfaceClass = MapService.class)
public class MapServiceImpl implements MapService {


    @Autowired
    private MapDao mapdao;


    public PageResult pageQuery(QueryPageBean queryPageBean) {
        String queryString = queryPageBean.getQueryString();
        Integer pageSize = queryPageBean.getPageSize();
        Integer currentPage = queryPageBean.getCurrentPage();
        PageHelper.startPage(currentPage,pageSize);
        Page<CheckMap> checkMapPage = mapdao.selectByCondition(queryString);

        return new PageResult(checkMapPage.getTotal(),checkMapPage.getResult());
    }

    @Override
    public void delete(Integer id) {
        mapdao.deleteById(id);
    }

    @Override
    public void add(CheckMap checkMap) {
        mapdao.add(checkMap);
    }

    @Override
    public CheckMap findById(Integer id) {

        CheckMap checkMap = mapdao.findById(id);
        return checkMap;
    }

    @Override
    public void edit(CheckMap checkMap) {
        mapdao.edit(checkMap);
    }

    @Override
    public List<CheckMap> findAllAddress() {
        List<CheckMap> list = mapdao.findAllAddress();
        System.out.println(list);
        return list;
    }
}
